package de.koller.occultation.engine.worldGen;

import de.koller.oceanFramework.OceanException;
import de.koller.oceanFramework.gl.util.RasterManager;

public class TileGenMap {

	private final RasterManager rasterBasic;

	public TileGenMap( int width, int height ) {
		rasterBasic = new RasterManager( width, height );
	}
	
	public void setBaseLayer( BaseLayer baseLayer, int mx, int my ) {
		rasterBasic.setPixel( getBaseLayerIndex( baseLayer ), mx, my );
	}
	
	public BaseLayer getBaseLayer( int mx, int my ) {
		int t = rasterBasic.colorAt( mx, my );
		for( BaseLayer b : BaseLayer.values() )
			if( getBaseLayerIndex( b ) == t )
				return b;
		throw new OceanException( "datatype: " + t + " is not supported" );
	}
	
	private int getBaseLayerIndex( BaseLayer baseLayer ) {
		switch( baseLayer ) {
			case WaterDeep:		return 0x00;
			case WaterLow:		return 0x01;
			case Sand:			return 0x02;
			case Grass:			return 0x03;
			default: return -1;
		}
	}
	
	public int getWidth() {
		return rasterBasic.getWidth();
	}
	
	public int getHeight() {
		return rasterBasic.getHeight();
	}
	
	public enum BaseLayer {
		WaterDeep, WaterLow, Sand, Grass;
	}
	
}
